#ifndef __NOTIFY_H__
#define __NOTIFY_H__

#include "base.pb.h"
#include "elog.h"
#include "elog_file.h"

#define WS_TEST_CLIENT_ID_1       "test_id_1"
#define WS_TEST_CLIENT_ID_2       "test_id_2"
#define WS_TEST_CLIENT_ID_3       "test_id_3"


class Notify {
public:
    Notify(Notify &other) = delete;
    void operator=(const Notify &) = delete;
    static Notify* getInstance();

    int handleMessage(WsPacket& ws_packet);
    int addWsMessage(WsPacket& ws_packet);
    int removeWsMessage(const std::string& ws_client_id, int cmd);
    int printfWsMessage();
    int pollWsMessage();

protected:
    Notify();
    ~Notify();

private:
    static Notify* pinstance_;

};

class NotifyWsMessage {
public:
    NotifyWsMessage(WsPacket& ws_packet) : ws_message(ws_packet) {
        send_count = 0;
    }

    WsPacket getWsMessage() const {
        return ws_message;
    }

    void printMessage() const {
        log_i("module_id = %d, cmd = %d, type = %d, client_id = %s", ws_message.module_id(), ws_message.cmd(), ws_message.type(), ws_message.client_id().c_str());
    }

    void addSendCount() {
        send_count++;
    }

public:
    WsPacket ws_message;
    int send_count;
};

class hash_fun {
public:
    size_t operator()(const NotifyWsMessage& message) const {
        std::string packet_serialized_data;
        message.ws_message.SerializeToString(&packet_serialized_data);
        return std::hash<std::string>()(packet_serialized_data);
    }
};

class mycmp {
public:
    bool operator()(const NotifyWsMessage &A, const NotifyWsMessage &B) const {
        return (A.ws_message.data() == B.ws_message.data());
    }
};

#endif                                                             